package com.example.a10928.weifriend.ui.personal_center

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import com.example.a10928.weifriend.App

import com.example.a10928.weifriend.R
import com.example.a10928.weifriend.http.api.VariableName
import com.example.a10928.weifriend.ui.BaseActivity
import com.example.a10928.weifriend.util.RxUtil
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_my_bank.*

class MyBankActivity : BaseActivity() {


    var id:String=""
    override fun initData() {

    }

    override fun initView() {
        supportActionBar?.hide()

        App.app().bpService.getUserBankCard(App.app().user.userId)
                .compose(RxUtil.io2mainLoad(this))
                .subscribe(
                        Consumer {
                            if(it.data==null){
                                toBindBank()
                            }else if(it.data.records==null){
                                toBindBank()
                            }else if(TextUtils.isEmpty(it.data.records.verify_card_no) ){
                                toBindBank()
                            }else{
                                tv_name.text=it.data.records.bank_name
                                tv_num.text=it.data.records.verify_card_no
                                id= it.data.records.verify_id.toString()

                            }



                        },
                        Consumer {
                            RxUtil.errorException(it)
                        }
                )

        tv_edit.setOnClickListener {
            var intent: Intent =Intent(this,BindBankActivity::class.java)
            intent.putExtra(VariableName.TYPE,"1")
            intent.putExtra(VariableName.DATA,id)
            startActivity(intent)
            finish()

        }

    }

    override fun getContentView(): Int {
        return R.layout.activity_my_bank
    }

    fun toBindBank(){
        var intent: Intent =Intent(this,BindBankActivity::class.java)
        intent.putExtra(VariableName.TYPE,"0")
        intent.putExtra(VariableName.DATA,"0")
        startActivity(intent)
        finish()
    }
}
